function handles = loadNewImage(handles)

if handles.loadMemMaps
    % load memory maps:
    load([handles.Pub.dataDestination 'memMaps'])
else
    memMaps = handles.memMaps;
end

try
    str = {'whole','win'};
    if handles.freqCompOn
        switch handles.ZPFtest
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            case 1 % pairwise ZPF test
                if handles.freqBand2 ~= handles.freqBand
                    if handles.freqBand2 > handles.freqBand
                        compDir = 1;
                    else
                        compDir = 2;
                    end
                    IDX = [0 2 4];
                    if ~strcmp(handles.Priv.computerInfo.endian,handles.endian)
                    handles.dataT = swapbytes( memMaps.(handles.Priv.PFMapName).(str{handles.win+1}...
                        ).([handles.Priv.prefixSession num2str(handles.dataset)...
                        ]).(handles.Priv.simM{3}).([handles.Priv.prefixFreqComp ...
                        num2str(handles.freqComp)]).Data.xyzc(:,:,:,IDX(handles.alpha)+compDir) );
                    else
                        handles.dataT = memMaps.(handles.Priv.PFMapName).(str{handles.win+1}...
                            ).([handles.Priv.prefixSession num2str(handles.dataset)...
                            ]).(handles.Priv.simM{3}).([handles.Priv.prefixFreqComp ...
                            num2str(handles.freqComp)]).Data.xyzc(:,:,:,IDX(handles.alpha)+compDir); 
                    end
                else
                    handles.dataT = zeros(handles.Priv.dataSize(handles.Priv.nrSessions,1:3));
                end
                %            if ~strcmp(handles.Priv.computerInfo.endian,handles.endian)
                %                handles.dataT = swapbytes(handles.dataT);
                %            end
                if handles.swapBytesOn % swap bytes if option is specified
                    handles.dataT = swapbytes(handles.dataT);
                end
                % normalize between zero and one:
                %            handles.dataT = handles.dataT/handles.subjPairs;
            case 2 % sum ZPF test
                if handles.freqBand2 ~= handles.freqBand
                    if handles.freqBand2 > handles.freqBand
                        K = 1;
                    else
                        K = -1;
                    end
                    if ~strcmp(handles.Priv.computerInfo.endian,handles.endian)
                        handles.dataT = swapbytes( memMaps.(handles.Priv.PFMapName).(str{handles.win+1}...
                            ).([handles.Priv.prefixSession num2str(handles.dataset)...
                            ]).(handles.Priv.simM{3}).([handles.Priv.prefixFreqComp ...
                            num2str(handles.freqComp)]).Data.xyzc(:,:,:,7) );
                    else
                        handles.dataT = memMaps.(handles.Priv.PFMapName).(str{handles.win+1}...
                            ).([handles.Priv.prefixSession num2str(handles.dataset)...
                            ]).(handles.Priv.simM{3}).([handles.Priv.prefixFreqComp ...
                            num2str(handles.freqComp)]).Data.xyzc(:,:,:,7);
                    end
                    %               if ~strcmp(handles.Priv.computerInfo.endian,handles.endian)
                    %                  handles.dataT = swapbytes(handles.dataT);
                    %               end
                    if handles.swapBytesOn % swap bytes if option is specified
                        handles.dataT = swapbytes(handles.dataT);
                    end
                    handles.dataT = K*handles.dataT;
                else
                    handles.dataT = zeros(handles.Priv.dataSize(handles.Priv.nrSessions,1:3));
                end
                
                %          handles.maxSc = max(handles.dataT(:));
                %          if handles.maxSc ~= 0
                %              handles.dataT = handles.dataT/handles.maxSc;
                %          end
        end
    else
        if handles.allFreq
            [handles.dataT,R] = freqComparison(handles,memMaps);
        else
            if handles.mapType == 1
                handles.dataT = memMaps.(handles.Priv.resultMapName).(str{handles.win+1}...
                    ).([handles.Priv.prefixFreqBand num2str(handles.freqBand-1)...
                    ]).([handles.Priv.prefixSession num2str(handles.dataset)...
                    ]).(handles.Priv.simM{handles.SimMeasure+2}).Data(handles.timeVal).xyz;
            else
                handles.dataT = memMaps.(handles.Priv.statMapName).(str{handles.win+1}...
                    ).([handles.Priv.prefixFreqBand num2str(handles.freqBand-1)...
                    ]).([handles.Priv.prefixSession num2str(handles.dataset)...
                    ]).(handles.Priv.simM{handles.SimMeasure+2}).Data(handles.timeVal).xyz(:,:,:,handles.mapType-1);
            end
            if ~strcmp(handles.Priv.computerInfo.endian,handles.endian)
                handles.dataT = swapbytes(handles.dataT);
            end
            if handles.swapBytesOn % swap bytes if option is specified
                handles.dataT = swapbytes(handles.dataT);
            end
        end
    end
    handles.repeatLoadingImages = 0;
catch
    lasterr
%    handles = couldNotRead(handles);
    return
end
clear memMaps

handles.maxSc = max(max(handles.dataT(:)),-1*min(handles.dataT(:)));
handles = updateThreshold(handles);

% quantize floating-point synchronization data:
if handles.freqCompOn && handles.ZPFtest == 2
    maxSc1 = max(handles.dataT(:));
    maxSc2 = abs(min(handles.dataT(:)));
    dataT1 = zeros(size(handles.dataT));
    dataT2 = zeros(size(handles.dataT));
    dataT1(handles.dataT>0) = handles.dataT(handles.dataT>0);
    dataT2(handles.dataT<0) = -1*handles.dataT(handles.dataT<0);
    dataT1(dataT1 >= handles.ScaleMax1) = handles.ScaleMax1;
    dataT1(dataT1 <= handles.ScaleMin1) = handles.ScaleMin1;
    dataT1 = (dataT1-handles.ScaleMin1)/handles.ScaleMax1;
    dataT1 = round(handles.colMapSize*dataT1);
    dataT2(dataT2 >= handles.ScaleMax1) = handles.ScaleMax1;
    dataT2(dataT2 <= handles.ScaleMin1) = handles.ScaleMin1;
    dataT2 = (dataT2-handles.ScaleMin1)/handles.ScaleMax1;
    dataT2 = round(handles.colMapSize*dataT2);
    dataT2 = dataT2 + handles.colMapSize+handles.rangeAnatomy;
    dataT2(dataT2==handles.colMapSize+handles.rangeAnatomy) = handles.ScaleMin1;
    handles.dataT = dataT1 + dataT2;
    handles.dataT = int16(handles.dataT);
    dataMax1 = min(single(maxSc1),single(handles.ScaleMax1));
    dataMax2 = min(single(maxSc2),single(handles.ScaleMax1));
    dataMax = max(dataMax1,dataMax2);
else
    handles.dataT(handles.dataT >= handles.ScaleMax1) = handles.ScaleMax1;
    handles.dataT(handles.dataT <= handles.ScaleMin1) = handles.ScaleMin1;
    handles.dataT = (handles.dataT-handles.ScaleMin1)/handles.ScaleMax1;
    handles.dataT = round(handles.colMapSize*handles.dataT);
    warning off
    handles.dataT = int16(handles.dataT);
    warning on
    dataMax = min(single(handles.maxSc),single(handles.ScaleMax1));
end

% return red colored brain region to its original color:
%if isfield(handles,'prevReg')
%    handles.dataAt(handles.dataAt == handles.colMapSize+...
%        handles.rangeAnatomy+handles.rangeAtlas) = handles.prevReg;
%end

% threshold maps:
if ( handles.Masking == 1 )
    if handles.MaskingType == 1
        % create mask based on current brain region:
        MaskedI = handles.atlas; % == handles.regionLabelsOrig(handles.CurrentRegion);
    else
        % create mask based on given threshold:
        warning off
        if handles.freqCompOn && handles.ZPFtest == 2
            MaxVal = max(max(dataT1(:)),max(dataT2(:)-handles.colMapSize-handles.rangeAnatomy));
            handles.TH = round(handles.Threshold*MaxVal/dataMax);
            MaskedI = (handles.dataT >= handles.TH & handles.dataT < handles.colMapSize) | (handles.dataT >= handles.TH + handles.colMapSize+handles.rangeAnatomy);
        else
            handles.TH = round((handles.Threshold*max( double(handles.dataT(:))) )/dataMax);
            MaskedI = handles.dataT >= handles.TH;
        end
        warning on
    end
    % overlay synchronization map on anatomical template:
    handles.SegIm = handles.anatomy;
    if handles.allFreq
        handles.SegIm(find(MaskedI)) = R(find(MaskedI));
    else
        handles.SegIm(find(MaskedI)) = handles.dataT(find(MaskedI));
    end
    % set image background to black by indexing last value in the colormap:
    handles.SegIm(handles.SegIm == 0) = size(get(gcf,'colormap'),1);
else
    % if no segmentation is specified, anatomical data is not needed:
    if handles.allFreq
        handles.SegIm = R;
    else
        handles.SegIm = handles.dataT;
    end
end

% overlay atlas on anatomical image:
%handles.dataAs = handles.anatomy;
%handles.dataAs(find(handles.dataAt)) = handles.dataAt(find(handles.dataAt));
%handles.dataAt = handles.dataAs;

% set background to black by indexing last value in the colormap:
%handles.dataAt(handles.dataAt == 0) = size(get(gcf,'colormap'),1);

% color currently activated brain region using red color:
%MI = handles.dataAt == handles.labels{handles.At}(handles.CurrentRegion)+handles.colMapSize + handles.rangeAnatomy+1;
%handles.prevReg = handles.labels{handles.At}(handles.CurrentRegion)+handles.colMapSize + handles.rangeAnatomy+1;
%handles.dataAt(MI) = handles.colMapSize+handles.rangeAnatomy+handles.rangeAtlas;

handles = setCurrentColorBar(handles);
